﻿Public Class Frm_Manajemen_Anggota_add

    Private Sub Frm_Manajemen_Anggota_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Call InisialisasiAplikasi()
        'Call openConnection()
    End Sub

    Private Sub Frm_Manajemen_Anggota_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txt_jurusan.Items.Add("Sistem Informasi")
        txt_jurusan.Items.Add("Teknik Informatika")
        txt_jurusan.Items.Add("Manajemen Bisnis Informatika")

        txt_NIM.Focus()

        Dim i As Integer
        For i = 1993 To 2020
            cmb_Tahun.Items.Add(i)
        Next i

        Call InisialisasiAplikasi()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        With OpenFileDialog1
            .Filter = "Image File (PNG, BMP, JPG, JPEG)|*.png;*.bmp;*.jpg;*.jpeg|" & _
                        "All File|*.*"

            If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                Try
                    lbl_filename.Text = .SafeFileName
                    pct_gambar.Image = Image.FromFile(.FileName)
                Catch ex As Exception

                End Try
            End If

        End With
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        pct_gambar.Image = Nothing
        lbl_filename.Text = "-"
    End Sub

 
    Private Sub cmdSave_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Validation.clearRules()
        Validation.addRules(txt_NIM.Text, "NIM", "required|length[1-7]")
        Validation.addRules(txt_Nama.Text, "Nama", "required|length[1-50]")
        Validation.addRules(txt_Tmp_Lahir.Text, "Tempat Lahir", "required|length[1-30]")
        Validation.addRules(txt_Alamat.Text, "Alamat", "required|length[1-150]")
        Validation.addRules(txt_Telp.Text, "Telepon", "required|numeric")
        Validation.addRules(txt_Email.Text, "E-mail", "required|email")
        ' Validation.addRules(txt_Jurusan.Text, "Jurusan", "required|length[1-100]")
        Validation.addRules(txt_Minat.Text, "Minat", "required|length[1-255]")



        If Validation.isValid Then

            '# operasi file image
            If lbl_filename.Text <> "-" Then
                With OpenFileDialog1
                    If .FileName <> vbNullString Then
                        My.Computer.FileSystem.CopyFile(.FileName, APP.PATH_IMG & lbl_filename.Text, True)
                    End If
                End With
            End If

            Db.FlushCache()
            Db.Insert("tbl_anggota")
            Db.SetField("nim", txt_NIM.Text)
            Db.SetField("nama", txt_Nama.Text)
            Db.SetField("tmp_lahir", txt_Tmp_Lahir.Text)
            Db.SetField("tgl_lahir", tanggal_lahir.Value)
            Db.SetField("alamat", txt_Alamat.Text)
            Db.SetField("telp", txt_Telp.Text)
            Db.SetField("email", txt_Email.Text)
            Db.SetField("jurusan", txt_Jurusan.Text)
            Db.SetField("tahun", cmb_Tahun.Text)
            Db.SetField("minat", txt_Minat.Text)
            Db.SetField("foto", lbl_filename.Text)

            If Connection.ExecuteNonQuery(Db.GetQueryString()) Then
                MsgBox("Data Berhasil Disimpan")
                'cmdSave_Click(sender, e)
            Else
                MsgBox("Gagal Menyimpan data")
            End If

        Else
            Validation.showMessage()
        End If
    End Sub

    Private Sub cmdCancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        txt_NIM.Text = ""
        txt_Nama.Text = ""
        txt_Tmp_Lahir.Text = ""
        tanggal_lahir.Value = Now
        txt_Alamat.Text = ""
        txt_Telp.Text = ""
        txt_Email.Text = ""
        txt_jurusan.Text = ""
        cmb_Tahun.Text = "- Tahun -"
        txt_Minat.Text = ""
        pct_gambar.Image = Nothing
        lbl_filename.Text = "-"
    End Sub
End Class